home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / diskutil / twister2.lzh / TWISTER.C < prev    next >
C/C++ Source or Header  |  1985-11-20  |  8KB  |  252 lines

  1. /********************************************************************
  2.  *                                                                  *
  3.  *                           The Twister                            *
  4.  *                               by                                 *
  5.  *                           David Small                            *
  6.  *                               and                                *
  7.  *                            Dan Moore                             *
  8.  *                                                                  *
  9.  *                                                                  *
  10.  *                             version 2                            *
  11.  *                                                                  *
  12.  *  Copyright (c) 1986 David Small and Daniel Moore for STart Mag.  *
  13.  *                                                                  *
  14.  ********************************************************************
  15.  *                                                                  *
  16.  *    Dedication:                                                   *
  17.  *       To Bill and all the other twisted cats in the world        *
  18.  *                                                                  *
  19.  ********************************************************************/
  20.  
  21. #include <portab.h>
  22. #include <gemdefs.h>
  23. #include <osbind.h>
  24. #include <obdefs.h>
  25. #include "twister.h"
  26. #include "twster.rsh"
  27.  
  28. /* something that should be in the compiler but isn't */
  29. #define void /* */
  30.  
  31. /* misc. defines */
  32. #define DESK      0
  33. #define WF_WXYWH  4
  34.  
  35. /* Stuff to call AES.  */
  36. WORD   contrl[12];
  37. WORD   intin[80];
  38. WORD   ptsin[256];
  39. WORD   intout[45];
  40. WORD   ptsout[12];
  41. WORD   msgbuf[8];
  42. WORD   VDIhandle;
  43.  
  44. /* external variables (defined in system library) */
  45. extern WORD gl_apid;
  46.  
  47. /* 
  48.  * hooks into the twister formatter code.
  49.  * These are passed as globals to avoid problems with
  50.  * passing params via Supexec().
  51.  *
  52.  * The actual twister format code is in mmtwst.c.  This file
  53.  * is common to both backup.prg and twister.prg. It is 
  54.  * located in the twister directory on the disk.
  55.  */ 
  56. extern twister();        /* the formatter, obviously          */
  57.  
  58. extern int thedisk,      /* drive number to format (A=0, B=1) */
  59.            dblsided,     /* sides (0 = single, -1 = double)   */
  60.            sectoroffset; /* offset for physical sector numbering */
  61. extern long buffer;      /* Track buffer for format.          */
  62. extern int badflag;      /* non-zero means a verify error     */
  63.  
  64. /* misc support routines */
  65. void
  66. setmem(p, n, c)
  67. register unsigned char *p;
  68. register unsigned int   n;
  69. register unsigned char  c;
  70. {
  71.      for (; n; n--)
  72.           *(p++) = c;
  73. }
  74.  
  75. void
  76. put_word(addr, val)
  77. register unsigned char *addr;
  78. register unsigned int   val;
  79. /* 
  80.  * Store val at the word at addr.  The data will be stored in low-high
  81.  * order, so it will be stored one byte at a time.
  82.  */
  83. {
  84.      *(addr++) = val & 0xff;
  85.      *addr     = (val >> 8) & 0xff;
  86. }
  87.  
  88. /* now the GEM supprot stuff */
  89. void
  90. init_gem()
  91. /* 
  92.  * setup the "resource" and the pointers to it.  Doing it here saves us from
  93.  * having a .rsc file on the disk which the user can forget to copy.       
  94.  */
  95. {
  96.      register int i, j;
  97.      WORD     work_in[11], work_out[57];
  98.      WORD     x, y, w, h;
  99.  
  100.      appl_init();   /* be trusting, assume it won't fail. (haha) */
  101.  
  102.      for (i = 0; i < 10; i++)
  103.           work_in[i] = 1;
  104.      work_in[10] = 2;
  105.  
  106.           /* don't want the char and box sizes */
  107.      VDIhandle = graf_handle(&x, &y, &w, &h);
  108.  
  109.      v_opnvwk(work_in, &VDIhandle, work_out); /* open virtual work stn */
  110.  
  111.      /* clear the screen, and then force a redraw of the dither */
  112.      v_clrwk(VDIhandle);
  113.      wind_get(DESK, WF_WXYWH, &x, &y, &w, &h);
  114.      form_dial(FMD_FINISH, 0L, 0L, x, y, w, h);
  115.  
  116.      /* 
  117.       * Now  adjust the object coordinates from character based to pixel
  118.       * based.  Also hook the strings to the string objects and buttons.  
  119.       */
  120.      for (i = j = 0; j < NUM_OBS; j++) {
  121.           rsrc_obfix(rs_object, j);           /* fix the coordinates system */
  122.           if (rs_object[j].type == G_STRING || rs_object[j].type == G_BUTTON)
  123.                rs_object[j].spec = rs_strings[i++];
  124.      }
  125. }
  126.  
  127. void
  128. cleartrack(num)
  129. int num;
  130. {
  131.      /* 
  132.       * clear a track.  Use buffer as a scratch area.
  133.       */
  134.      setmem(buffer, (512 * 10), 0);
  135.  
  136.      Flopwr(buffer, 0L, thedisk, 1, num, 0, 10);  /* write 10 sectors */
  137.      
  138.      if (dblsided)
  139.           Flopwr(buffer, 0L, thedisk, 1, num, 1, 10); /* 10 more on the back */
  140. }
  141.  
  142. extern exit();
  143. asm {
  144. exit:     dc.w 0         /* just a place holder to fool the linker */
  145. }
  146.  
  147. void
  148. main() 
  149. {
  150.      WORD x, y, w, h, which;
  151.  
  152.      /*
  153.       * tell GEM hello.
  154.       * we're glad to see him too.
  155.       */
  156.      init_gem();
  157.  
  158.      /* 
  159.       * Next allocate the track buffer.
  160.       * Give it 16K.  We "should" only need a little less than 
  161.       * 8K, but it never hurts to have to much.
  162.       */
  163.      buffer = Malloc(0x4000L);
  164.  
  165.      sectoroffset = 0;   /* number sectors 1 to 10 not 11 to 20 */
  166.  
  167.      /* set the default buttons */
  168.      rs_object[LONELY].state |= SELECTED;
  169.      rs_object[DRIVE0].state |= SELECTED;
  170.  
  171.      /* put up the dialog */
  172.      form_center(rs_object, &x, &y, &w, &h);
  173.      form_dial(FMD_START, 0, 0, 0, 0, x, y, w, h);
  174.      objc_draw(rs_object, ROOT, 9, x-1, y-1, w+2, h+2);
  175.  
  176.      for(;;) {
  177.           graf_mouse(0, 0L);  /* arrow */
  178.  
  179.           /* 
  180.            * As you may gather, this isn't the normal form_do.
  181.            * If you are using the normal one (highly likely 
  182.            * since you don't have mine) just remove the 
  183.            * ", 0L, 0L" from the call.  
  184.            */
  185.           which = form_do(rs_object, 0, 0L, 0L);
  186.  
  187.           if (which == RUNAWAY)
  188.                break;         /* they don't want us.  boo hoo */
  189.  
  190.           graf_mouse(2, 0L);  /* busy bee */
  191.  
  192.           /* 
  193.            * setup the input parameters for the format.
  194.            */
  195.           if (rs_object[DRIVE0].state & SELECTED)
  196.                thedisk = 0;        /* format drive A */
  197.           else 
  198.                thedisk = 1;        /* otherwise drive B */
  199.  
  200.           if (rs_object[MARRIED].state & SELECTED)
  201.                dblsided = -1;      /* double sided   */
  202.           else
  203.                dblsided = 0;       /* single sided   */
  204.  
  205.           Supexec(twister);   /* run the formatter in super mode */
  206.  
  207.           if (!badflag) {     /* good disk? */
  208.                /*
  209.                 * Yes, now set it up as a GEMDOS disk.
  210.                 *
  211.                 * First clear the fat and directory sectors.
  212.                 * Simpliest is to just clear the first few tracks 
  213.                 */
  214.                cleartrack(0);
  215.                cleartrack(1);
  216.  
  217.                /* now prototype the boot sector */
  218.            /* this is where version 1.0 had a bug, it wrote the
  219.                 * same serial number on all disks
  220.             */
  221.                Protobt(buffer, 0x02000000L, (dblsided ? 3 : 2), 0);
  222.  
  223.                /* now change the sectors per track entry.  (10 not 9) */
  224.                put_word(buffer + 0x18, 10);
  225.  
  226.                /* next is the sectors on media entry. */
  227.                put_word(buffer + 0x13, (dblsided ? 1600 : 800));
  228.  
  229.                /* and finally write the boot sector */
  230.                Flopwr(buffer, 0L, thedisk, 1, 0, 0, 1);
  231.           }
  232.           else {
  233.                graf_mouse(0, 0L);  /* arrow */
  234.                form_alert(1, "[3][There was error formatting|the disk.][Abort]");  
  235.           }
  236.  
  237.           /* deslect the format button */
  238.           rs_object[TWISTIT].state &= ~SELECTED;
  239.           objc_draw(rs_object, TWISTIT, MAX_DEPTH, x, y, w, h);
  240.      }
  241.  
  242.      Mfree(buffer);      /* give it back to TOS */
  243.  
  244.      /* tell GEM bye, bye */
  245.      form_dial(FMD_FINISH, 0L, 0L, x, y, w, h); /* force a redraw */
  246.      v_clsvwk(VDIhandle);
  247.      appl_exit();
  248.  
  249.      _exit(0);       /* wave bye, bye to the nice user */
  250. }    
  251.  
  252.